﻿using Gadgeteer.Interfaces.Graphics;
using Microsoft.SPOT;
using System;

namespace Gadgeteer.Interfaces.Fakes
{
    public class FakeGraphics : ISimpleGraphics
    {
        public FakeGraphics()
        {
            Height = 200;
            Width = 300;
        }

        private Bitmap bitmap;

        public Picture Current
        {
            get { return new Picture(bitmap.GetBitmap(), Picture.PictureEncoding.BMP); }
        }

        public void DisplayImage(Picture picture, uint x, uint y)
        {
            bitmap = picture.MakeBitmap();
        }

        public void Clear()
        {
            bitmap = null;
            lastText = null;
        }

        public bool AutoRedraw { get; set; }

        public Color BackgroundColor { get; set; }

        public uint Height { get; set; }

        public uint Width { get; set; }

        private string lastText;
        public string LastText { get { return lastText; } }

        public void DisplayText(string text, Microsoft.SPOT.Font font, Color color, uint x, uint y)
        {
            lastText = text;
        }

        public void ClearNoRedraw()
        {
            Clear();
        }

        public Color GetPixel(int x, int y)
        {
            if (bitmap != null)
            {
                if (bitmap.Width > x && bitmap.Height > y)
                {
                    return bitmap.GetPixel(x, y);
                }

            }

            return Color.Black;
        }

        public void SetPixel(Color color, uint x, uint y)
        {
            if (bitmap != null)
            {
                if (bitmap.Width > x && bitmap.Height > y)
                {
                    bitmap.SetPixel((int)x, (int)y, color);
                }

            }
        }
    }
}
